package services;

import java.awt.Color;

import javax.swing.JOptionPane;

import enums.GameOverStateEnum;

import manager.Start;

/**
 * This service contains all State methods that repeat frequently
 * @author Netanel
 *
 */
public class StateService {

	/**
	 * The method will pop up the relevant message in case the
	 * game is over
	 */
	public static void handleGameOver() {
		if (Start.getState().getGameOverState() == GameOverStateEnum.BLACK_WINNER) {
			JOptionPane.showMessageDialog(Start.getGame(), "You are the winner!", "Winner!", 0);
			System.exit(0);
		}
		else if (Start.getState().getGameOverState() == GameOverStateEnum.WHITE_WINNER) {
			JOptionPane.showMessageDialog(Start.getGame(), "The computer is the winner!", "Winner!", 0);
			System.exit(0);
		}
		else if (Start.getState().getGameOverState() == GameOverStateEnum.GAME_DRAW) {
			JOptionPane.showMessageDialog(Start.getGame(), "The game end by draw..", "Draw!", 0);
			System.exit(0);
		}
	}

	/**
	 * The method returns current turn color
	 * @return
	 */
	public static Color currentTurnColor() {
		return Start.getState().getTurn();
	}
	
	/**
	 * The method returns true if the game is over
	 * @return
	 */
	public static boolean isGameOver() {
		return Start.getState().getGameOverState() != GameOverStateEnum.NO_WINNER;
	}
	
	/**
	 * update the GameOverState on State with the enum given
	 * @param gameOverState
	 */
	public static void updateGameOverEnum(GameOverStateEnum gameOverState) {
		Start.getState().setGameOverState(gameOverState);
	}
	
	/**
	 * update the turn on State with the turn color given
	 * @param turn
	 */
	public static void updateTurn(Color turn) {
		Start.getState().setTurn(turn);
	}
}
